package bs.app.Client;

import android.os.Build;
import android.util.Config;
import bs.app.Constant.CConfig;
import bs.app.Main.CCanvas;
import bs.app.Position.CPosition;
import bs.app.Res.CRess;
import bs.app.android.Graphics;
import bs.app.android.Sprite;

public class ItemApp
{
	public String Name,Description,Date,Price,DownLoad,Demo;
	public String Link;
	public int x,y,w,h;
	public int row,colum;
	public boolean isFocus;
	public int xFocus,yFocus;
	public int xName,yName;
	public int xDescription,yDescription;
	public int xDate,yDate,xPrice,yPrice;
	public int NumberPage=0;
	public int xLine,yLine;
	public int distanceRegion;
	public int[] Color={0xa1a6a1,0xf1941c};
	public int[] Bordercolor={0x090b7a,0x442005};
	public int[] datecolor={0x8a8c8b};
	public int indexcolor,indexborder,indexDateColor; 
	public int sorating;
	public int khoangcach=6;
	public int yImage=0;
	public ItemApp()
	{
		
	}
	
	// code xu ly chay chu
	int deltax = 0;
	public void paintIconApppage1(Graphics g)
	{
		g.drawImage(CRess.IconApp[row][colum], x, y, CPosition.ANCHOR_LEFT_TOP);
		if(isFocus==true)
		{
			g.drawImage(CRess.imgFocus, x-xFocus, y-yFocus, CPosition.ANCHOR_LEFT_TOP);
		}
		
		
		if(Name!=null && !Name.trim().equals(""))
		{
			String[] TempName=null;
			TempName=CCanvas.mediumfont.splitStrInLine(Name, CCanvas.xTranslate+CCanvas.s_iWcanvas-(x+xName + 20));	 //namnv +20		
			if(TempName.length>1)
				TempName[0]+="...";
//			CCanvas.mediumfont.drawString(g, TempName[0], x + xName, y+yName, 0,  Color[indexcolor],Bordercolor[indexborder],true);
			CCanvas.mediumfont.drawString(g, TempName[0], x + xName + 3, y+yName, 0,  Color[indexcolor],Bordercolor[indexborder],true);
		}
		if(Description!=null && !Description.trim().equals(""))
		{
			String[] TempDescription=null;
//			TempDescription=CCanvas.smallfont.splitStrInLine(Description, CCanvas.xTranslate+240-xDescription);
			TempDescription=CCanvas.smallfont.splitStrInLine(Description, CCanvas.s_iWcanvas-xDescription -5); //namnv -5
			if(TempDescription.length>1)
			{	
				if(TempDescription.length>2)TempDescription[1]+="...";
				for(int i=0;i<2;i++)
					CCanvas.smallfont.drawString(g, TempDescription[i] + "tanloc", x+xName, yDescription+i*15, 0, 0xffffff,0x9d9f9e,false);
			}
            else
                CCanvas.smallfont.drawString(g, TempDescription[0] + "tanloc", x+xName, yDescription+5, 0, 0xffffff,0x9d9f9e,false);
		}
		if(Date!=null && !Date.trim().equals(""))
		{
			CCanvas.smallfont.drawString(g, Date, xDate, yDate, 0, datecolor[indexDateColor],0x9d9f9e,false);
		}
		if(Price!=null && !Price.trim().equals(""))
		{
			g.drawImage(CRess.Money, xPrice+1+CRess.download.getWidth()+CCanvas.mediumfont.stringWidth("Download")-5-khoangcach, yPrice+27 , Graphics.TOP|Graphics.LEFT);
			CCanvas.smallfont.drawString(g,Price, xPrice+0+CRess.download.getWidth()+CCanvas.mediumfont.stringWidth("Download")+CRess.Money.getWidth()-khoangcach, yPrice+27, 0, 0xc5b957,0xf8f8ff,false);
		}
		if(DownLoad!=null && !DownLoad.trim().equals(""))
		{
			g.drawImage(CRess.download, xPrice-khoangcach, yPrice+29, Graphics.TOP|Graphics.LEFT);
			CCanvas.smallfont.drawString(g,DownLoad, xPrice+3+CRess.download.getWidth()-khoangcach, yPrice+27, 0, 0xffffff,0x9d9f9e,false);
//			//System.out.println("sorating:"+ sorating);
//			for(int i=0;i<sorating;i++){
//				//System.out.println("x:"+(x+i*6) + "  y + h -5:"+(y + h -5));
//				g.drawImage(CRess.imgrating, x+i*6, y + h -5, Graphics.TOP|Graphics.LEFT);
//			}
		}
		if(Demo!=null && !Demo.trim().equals(""))
		{
			CCanvas.smallfont.drawString(g,Demo, xPrice+100, yPrice+32, 0, 0xffffff,0x9d9f9e,false);
		}
	}
	
	public void paintIconApppage2(Graphics g)
	{
		
		
	}
	
	public void paintIcon(Graphics g)
	{
		if(CRess.IconApp[row][colum]!=null)
		{
			if(NumberPage==1)
			{
				g.drawImage(CRess.IconApp[row][colum], x, y, CPosition.ANCHOR_LEFT_TOP);
				if(isFocus==true)
				{
					g.drawImage(CRess.imgFocus, x-xFocus, y-yFocus, CPosition.ANCHOR_LEFT_TOP);
				}
			}else if(NumberPage==2){
				
				g.setColor(80,79,79);
				g.drawLine(xLine, yLine, CCanvas.s_iWcanvas, yLine);
				g.drawLine(xLine, yLine+h,  CCanvas.s_iWcanvas, yLine+h);
				if(isFocus==true)
				{	
					if( CCanvas.s_iWcanvas <CRess.imgFocus.getWidth() ){
						g.drawRegion(CRess.imgFocus, 0, 0,  CCanvas.s_iWcanvas, distanceRegion, Sprite.TRANS_NONE, x-xFocus , y-yFocus, CPosition.ANCHOR_LEFT_TOP);
					}else{
						for(int i =0; i < CCanvas.s_iWcanvas + CRess.imgFocus.getWidth();i+=CRess.imgFocus.getWidth()){
							g.drawRegion(CRess.imgFocus, 0, 0,  CRess.imgFocus.getWidth(), distanceRegion, Sprite.TRANS_NONE, x-xFocus + i, y-yFocus, CPosition.ANCHOR_LEFT_TOP);	
						}		
					}
				}
				g.drawImage(CRess.IconApp[row][colum], x, y + yImage, CPosition.ANCHOR_LEFT_TOP);
			}
		}
		
		if(Name!=null && !Name.trim().equals(""))
		{
			//String[] TempName=null;
			//TempName=CCanvas.mediumfont.splitStrInLine(Name, CCanvas.xTranslate+CCanvas.s_iWcanvas-(x+xName + 20));	 //namnv +20		
			//if(TempName.length>1)
			//	TempName[0]+="...";
//			CCanvas.mediumfont.drawString(g, TempName[0], x + xName, y+yName, 0,  Color[indexcolor],Bordercolor[indexborder],true);
			if(NumberPage == 2)
			{
				g.setClip(x + xName, CConfig.HIEGHT_TITLE + CConfig.FONT_TITLE_MENU + 5, 240, CCanvas.s_iHcanvas - CConfig.HIEGHT_COMMNAND - CConfig.HIEGHT_TITLE);//y+yName, 15				
				
				int lenght = Name.length();
				if(lenght > 30 && isFocus==true)
				{
					//itime++;
					//if(itime > 1)
					//{
						//itime = 0;
						deltax-=1;
						if(deltax < - ((lenght - 30) * 7) - 10 )
							deltax = 0;
					//}
				}
			}
			
			CCanvas.mediumfont.drawString(g,Name, x + xName + 3 + deltax, y+yName + 8, 0,  Color[indexcolor],Bordercolor[indexborder],true);
					
			if(NumberPage == 2)
			{
				g.setClip(0, CConfig.HIEGHT_TITLE + CConfig.FONT_TITLE_MENU + 5, CCanvas.s_iWcanvas,
					CCanvas.s_iHcanvas - CConfig.HIEGHT_COMMNAND - CConfig.HIEGHT_TITLE - CConfig.FONT_TITLE_MENU - 5);
			}
			
		}
		if(Description!=null && !Description.trim().equals(""))
		{
			String[] TempDescription=null;
//			TempDescription=CCanvas.smallfont.splitStrInLine(Description, CCanvas.xTranslate+240-xDescription);
			TempDescription=CCanvas.smallfont.splitStrInLine(Description, CCanvas.s_iWcanvas-xDescription -5); //namnv -5
			if(TempDescription.length>1)
			{	
				if(TempDescription.length>2)TempDescription[1]+="...";
				for(int i=0;i<2;i++)
					CCanvas.smallfont.drawString(g, TempDescription[i], x+xName, yDescription+i*15 + 3, 0, 0xffffff,0x9d9f9e,false);
			}
            else
                CCanvas.smallfont.drawString(g, TempDescription[0], x+xName, yDescription+8, 0, 0xffffff,0x9d9f9e,false);
		}
		if(Date!=null && !Date.trim().equals(""))
		{
			CCanvas.smallfont.drawString(g, Date, xDate, yDate, 0, datecolor[indexDateColor],0x9d9f9e,false);
		}
		if(Price!=null && !Price.trim().equals(""))
		{
			g.drawImage(CRess.Money, xPrice+1+CRess.download.getWidth()+CCanvas.mediumfont.stringWidth("Download")-5-khoangcach, yPrice+27 , Graphics.TOP|Graphics.LEFT);
			CCanvas.smallfont.drawString(g,Price, xPrice+0+CRess.download.getWidth()+CCanvas.mediumfont.stringWidth("Download")+CRess.Money.getWidth()-khoangcach, yPrice+27, 0, 0xc5b957,0xf8f8ff,false);
		}
		if(DownLoad!=null && !DownLoad.trim().equals(""))
		{
			g.drawImage(CRess.download, xPrice-khoangcach, yPrice+29, Graphics.TOP|Graphics.LEFT);
			CCanvas.smallfont.drawString(g,DownLoad, xPrice+3+CRess.download.getWidth()-khoangcach, yPrice+27, 0, 0xffffff,0x9d9f9e,false);
//			//System.out.println("sorating:"+ sorating);
//			for(int i=0;i<sorating;i++){
//				//System.out.println("x:"+(x+i*6) + "  y + h -5:"+(y + h -5));
//				g.drawImage(CRess.imgrating, x+i*6, y + h -5, Graphics.TOP|Graphics.LEFT);
//			}
		}
		if(Demo!=null && !Demo.trim().equals(""))
		{
			CCanvas.smallfont.drawString(g,Demo, xPrice+100, yPrice+32, 0, 0xffffff,0x9d9f9e,false);
		}
	}
	public void Paint(Graphics g)
	{
		paintIcon(g);
	}
}
